<!-- eslint-disable -->
<template>
    <div class="container" :style="{minHeight : offsetheight + 'px'}">

        <template v-if="loading" style="text-align:center;">
            <van-row>
                <van-col span="24" style="margin-top:30%; text-align:center;">
                    <van-loading type="spinner" color="#ffffff" size="48px"
                                 text-size="24px" vertical>
                        查询中
                    </van-loading>
                </van-col>
            </van-row>
        </template>

        <template v-else>
            <div class="header">
<!--                <div class="title-tip">快递外卖人员专用出入</div>-->
                <div class="title-main">通&nbsp;&nbsp;行&nbsp;&nbsp;证</div>
            </div>
            <div class="body">
                <div class="img-item"
                     v-if="tel !== ''">
                    <div v-lazy-container="{ error: loadingImg }">
                        <img class="hd-img-responsive" :data-src="user_img">
                    </div>
                    <div class="userInfo">
                        <van-row>
                            <van-col span="20">
                                {{name}}
                            </van-col>
                            <van-col span="4">
                                {{health_type}}
                            </van-col>
                            <van-col span="24" class="tel-item">
                                {{tel}}
                            </van-col>
                            <van-col span="24">
                                公司名称：{{worker_type}}
                            </van-col>
                            <van-col span="24">
                                工作类型：{{work_type}}
                            </van-col>
                        </van-row>
                    </div>
                </div>
                <van-row class="bottom-item">
                    <van-col span="18">
                        <van-col span="24">
                            沈阳市房产局
                        </van-col>
                        <van-col span="24">
                            沈阳市民政局
                        </van-col>
                    </van-col>
                    <van-col span="6" class="bottom-right">
                        监制
                    </van-col>
                </van-row>
            </div>
            <div class="footer"></div>
        </template>

        <div class="dialog-item" v-if="dialogShow">
            <van-row>
                <van-col class="dialog-title" span="24">
                    提示
                </van-col>
                <van-col class="dialog-content" span="24">
                    <van-col span="24">
                        <van-icon name="info-o" />
                    </van-col>
                    <van-col span="24">
                        通行证状态异常<br>
                        请重新扫描二维码
                    </van-col>
                </van-col>
            </van-row>
        </div>
    </div>
</template>

<script>
import { insertUserPermitPlace, getWorkerDetailInfoList } from '@/api/yi-qing-fang-kong.js'
import { getAgeByIdCard } from '@/libs/tools'
// import { passType } from '@/libs/dist'

export default {
  data () {
    return {
      loadingImg: 'https://skv4.oss-cn-hangzhou.aliyuncs.com/app/skv4/common1584267495000/loadingImg.jpg',
      user_img: '',
      dialogShow: false,
      name: '',
      tel: '',
      worker_type: '暂无数据',
      work_type: '暂无数据',
      health_type: '健康',
      userinfo: {
        type: 1
      },
      offsetheight: document.documentElement.clientHeight,
      qrColor: ['', '#0DBB22', '#00A2E6', '#FFEF00', '#E9611D', '#A865CF', '#E30920'],
      fontColor: ['', '#FFFFFF', '#000000', '#FFFFFF', '#FFFFFF'],
      borderColor: ['', '#0DBB22', '#00A2E6', '#FFEF00', '#E9611D', '#A865CF', '#E30920'],
      loading: true,
      // 经度
      lng: '123.410782',
      // 纬度
      lat: '41.789928'
    }
  },

  props: {},

  components: {},

  computed: {
    getColor () {
      return this.qrColor[this.userinfo.type]
    }
  },

  methods: {
    getLocation () {
      const randomNum = this.$route.query && this.$route.query.randomNum
      console.log('位置-获取的随机码', randomNum)
      let isSuccess = false// 获取位置成功还是失败
      let _this = this
      if (!isSuccess) {
        this.$common.getLocation(function (option) {
          _this.lng = option.longitude
          _this.lat = option.latitude
          console.log(_this.lng, '获取后经度')
          console.log(_this.lat, '获取后纬度')
          // 存入信息
          const param = {
            qrcode: randomNum,
            longitude: _this.lng,
            latitude: _this.lat
          }
          _this.insertUserPermitPlace(param)
        })
        isSuccess = true
        console.log('默认经度', this.lng)
        console.log('默认纬度', this.lat)
      }
    },
    insertUserPermitPlace (data) {
      insertUserPermitPlace(data).then(ret => {
        console.log(ret.data, '返回的信息')
        if (ret.data.errcode === 0) {
          this.loading = false
          this.userinfo = ret.data.data
          this.name = ret.data.data.name
          this.getWorkerDetailInfoList(ret.data.data.name, ret.data.data.card_no)
          this.tel = this.changeTel(ret.data.data.tel)
          this.user_img = 'https://life-photo.oss-cn-beijing.aliyuncs.com/' + ret.data.data.card_no + '.jpg'
          this.userinfo['age'] = getAgeByIdCard(this.userinfo.card_no)
        } else {
          this.dialogShow = true
          // this.$notify({ type: 'danger', message: '请重新扫描二维码' })
        }
      })
    },
    changeTel (data) {
      var tel = data.substr(0, 3) + '****' + data.substr(7)
      return tel
    },
    getWorkerDetailInfoList (name, card_no) {
      let data = {
        name: name,
        card_no: card_no
      }
      getWorkerDetailInfoList(data).then(ret => {
        console.log(ret.data, '返回的信息')
        if (ret.data.errcode === 0) {
          let new_list = []
          let work_type_list = []
          for (let i = 0; i < ret.data.data.length; i++) {
            if (ret.data.data[i].health_type === '1') {
              this.health_type = '异常'
            }
            new_list.push(ret.data.data[i].work_name)
            if (ret.data.data[i].type === '1') {
              work_type_list.push('外卖')
            }
            if (ret.data.data[i].type === '2') {
              work_type_list.push('快递')
            }
          }
          work_type_list = this.unique(work_type_list)
          this.worker_type = new_list.join()
          this.work_type = work_type_list.join()
        }
      })
    },
    unique (arr) {
      return Array.from(new Set(arr))
    }
  },

  watch: {},

  mounted () {
    this.getLocation()
  }

}
</script>

<style scoped lang="less">
    @borderColor: #00A2E6;
    .type1 {
        border: 1px solid #0dbb22;
    }

    .type2 {
        border: 1px solid #ffff00;
    }

    .type3 {
        border: 1px solid #e9611d;
    }

    .type4 {
        border: 1px solid #e30920;
    }

    .c1 {
        color: #0dbb22;
    }

    .c2 {
        color: #ffff00;
    }

    .c3 {
        color: #e9611d;
    }

    .c4 {
        color: #e30920;
    }

    /*.title {
        color: #363636;
        font-weight: bold;
    }*/

    .value {
        color: #787878;
    }

    .main-tip {
        position: absolute;
        top: 70%;
        left: 2%;
        right: 2%;
        text-align: center;
        font-size: 24px;
        font-weight: 700;
    }

    .table-info {
        padding: 0px 4px 0 4px;
        border: 1px solid;

        .table-info-row {
            display: flex;
            align-items: center;
        }

        .table-info-row2 {
            height: 45px;

            .table-right-border {
                border-right: 1px solid;
            }

            .table-left-border {
                margin-left: -1px;
                border-left: 1px solid #DDDDDD;
                padding: 5px 0 5px 0;
            }

            .table-right-border-end {
                padding: 5px 0 5px 0;
            }

            .table-info-row2-col {
                height: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
            }
        }

        .table-col {
            display: flex;
            align-items: center;
            padding: 5px 0 5px 0;

            .address-width {
                width: 50px;
            }
        }
    }

    .user-info {
        padding: 5px 10px 10px 10px;

        .name {
            color: #363636;
            font-weight: bold;
        }

        .address {
            font-size: 14px;
        }
    }

    .imgStyle {
        width: 100%;
        border: 1px solid @borderColor;
    }

    /*新版样式部分*/
    .container {
        background-image: url("../../../assets/images/showinfo/public-success-bg.jpeg");
        color: #ffffff;
    }

    .header {
        padding-top: 20%;
        text-align: center;
    }

    .title-tip {
        color: #f2f5f9;
        font-size: 20px;
        font-weight: bold;
    }

    .title-main {
        color: #ffffff;
        font-size: 48px;
        font-weight: bold;
        text-align: center;
    }

    .body {
        margin-top: 10px;
        font-size: 12px;
        text-align: center;
        padding: 0 18%;
        /*position: relative;*/
    }

    .img-item {
        width: 100%;
        height: 14.75rem;
        position: relative;
    }
    .img-item img{
        /*height: 14.75rem;*/
    }

    .userInfo {
        background: rgba(0, 0, 0, 0.5);
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 10px 0;
    }

    .userInfo .van-row {
        padding: 0 10px;
        text-align: left;
    }

    .userInfo .van-col {
        margin-bottom: 5px;
    }

    .tel-item {
        letter-spacing: 2px;
        font-size: 14px;
    }

    .bottom-item {
        position: absolute;
        bottom: 40px;
    }

    .bottom-item .van-col--24 {
        height: 20px;
        line-height: 20px;
    }

    .bottom-right {
        height: 40px;
        line-height: 40px;
    }

    .dialog-item{
        position: fixed;
        top: 25%;
        bottom: 35%;
        /*left: 20%;*/
        /*right: 20%;*/
        width: 100%;
        border-radius: 5px;
        /*padding: 0 20%;*/
    }

    .dialog-item .van-row{
        height: 100%;
        padding: 0 15%;
    }
    .dialog-title{
        width: 100%;
        background-color: #33b384;
        font-size: 14px;
        padding: 15px;
        text-align: center;
        border-top-right-radius: 5px;
        border-top-left-radius: 5px;
    }
    .dialog-content{
        background: #ffffff;
        height: 100%;
        border-bottom-right-radius: 5px;
        border-bottom-left-radius: 5px;
        color: orangered;
        text-align: center;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
    }
    .van-icon-info-o{
        font-size: 50px;
    }
    .van-loading__text{
        color: #ffffff;
    }
</style>
